package com.worldcup.service.impl;

import com.worldcup.dao.TravelMapper;
import com.worldcup.model.Travel;
import com.worldcup.service.TravelService;
import com.worldcup.service.help.TravelMatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author duwan.zq
 * @date 2018/05/23
 */
@Service
public class TravelServiceImpl implements TravelService{

    private final static Logger logger = LoggerFactory.getLogger(TravelServiceImpl.class);

    @Autowired
    private TravelMapper travelMapper;

    @Autowired
    private List<TravelMatch> travelMatches;

    @Override
    public List<String> getAllOpenid() {
        return travelMapper.getAllOpenid();
    }

    @Override
    public List<Travel> getTravel(String openid) {
        return getTravel(openid, null);
    }

    @Override
    public List<Travel> getTravel(String openid, Integer travelType) {
        return travelMapper.getTravelListByOpenid(openid, travelType);
    }

    @Override
    public Integer calMatching(String openid, String calOpenid) {
        if(openid.equals(calOpenid)){
            return null;
        }
        List<Travel> travels = getTravel(openid);
        List<Travel> referTravels = getTravel(calOpenid);
        //基准匹配度
        int matchRate = 50;
        for(TravelMatch travelMatch : travelMatches){
            if(travelMatch.isMatch(travels, referTravels)){
                matchRate += 10;
            }
        }
        return matchRate;
    }
}
